package com.atguigu.spzx.cart.client.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Component
public class SpzxCartRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        //配置请求头： 因为cart服务需要使用token获取用户id 再获取对应的购物车
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        String token = requestAttributes.getRequest().getHeader("token");

        template.header("token" , token);

    }
}
